package org.water.sys.repository;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.water.base.repository.BaseRepository;
import org.water.sys.entity.SysRole;

/**
 * 角色 dao
 * @author qzy
 *
 */
public interface RoleDao extends BaseRepository<SysRole, String> {

	/**
	 * 查询角色
	 * @param roleName
	 * @param pageRequest
	 * @return
	 */
	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") })
	public Page<SysRole> findByRoleNameLike(String roleName,Pageable pageRequest);
	/**
	 * 不包含用户组拥有的权限
	 * @param groupId
	 * @return
	 */
	@Query(value="select t from SysRole t  where t.id not in ( select gr.roleId from SysGroupRole gr where gr.groupId=?1 ) ")
	//@Query(value="select r.id,r.role_name,r.remark from sys_role r"
	//		+ " where r.id not in (select gr.role_id from sys_group_role gr where gr.group_id=?1 )",nativeQuery=true)
	public List<SysRole> findNotContainsGroupRole(String groupId);
}
